package com.jn.news.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.jn.news.R;
import com.jn.news.model.NewsClassifyDto;
import com.jn.news.ui.TianxingNewsListActivity;
import com.jn.news.utils.Constant;

;


//订单列表适配器
public class NewsClassifyAdapter extends BaseAdapter<NewsClassifyDto, NewsClassifyAdapter.MyViewHolder> {


    private OnItemClickListener onItemClickListener;

    public NewsClassifyAdapter(Context context) {
        super(context);
    }


    @Override
    protected int onBindLayout() {
        return R.layout.item_news_classify;
    }

    @Override
    protected MyViewHolder onCreateHolder(View view) {
        return new MyViewHolder(view);
    }

    @Override
    protected void onBindData(MyViewHolder holder, NewsClassifyDto newsClassifyDto, int position) {
        //标题
        holder.tvClassify.setText(newsClassifyDto.getName());
        //时间
        holder.tvClassifyIns.setText(newsClassifyDto.getJianjie());

        holder.clToNewsList.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, TianxingNewsListActivity.class);
                intent.putExtra(Constant.NEWS_TYPE,newsClassifyDto.getColid());
                intent.putExtra(Constant.NEWS_TYPE_NAME,newsClassifyDto.getName());
                mContext.startActivity(intent);
            }
        });
    }


    public interface OnItemClickListener{
        void onItemClick(int position);


    }
    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener = onItemClickListener;
    }
    class MyViewHolder extends RecyclerView.ViewHolder {


        ConstraintLayout clToNewsList;
        TextView tvClassify;
        TextView tvClassifyIns;


        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            tvClassify = itemView.findViewById(R.id.tv_classify);
            tvClassifyIns = itemView.findViewById(R.id.tv_classify_ins);
            clToNewsList = itemView.findViewById(R.id.cl_to_news_list);
        }
    }
}
